<?php
namespace Home\Controller;
use Think\Controller;
class RegisterController extends Controller {
	public function index(){

		if(isset($_SESSION['username'])){
        	$this->assign('login','true');
        	$this->assign('username',$_SESSION['username']);
        }

        //当前登录用户的id
        $userId=$_SESSION['id'];

  

		$this->display();
	}

     //退出
    public function doLogout(){
        $_SESSION = array();
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'',time()-1,'/');
        }
        session_destroy();
        $this->redirect('Index/index');
    }

    public function doReg(){
        
        $password = $_POST['password'];
        $repassword = $_POST['repassword'];
        $phone = $_POST['phone'];
        $address = $_POST['address'];
        $username = $_POST['username'];

        if($password != $repassword){
            $this->error('两次密码必须一致');

        } else{
            $user = D('user');
            if(!$user->create()){
                $this->error($user->getError());
            }

            $lastId = $user->add();
            if ($lastId){
                $this->redirect('Login/index');
            }else {
                $this->error('创建失败,请检查信息！');
            }
        }         
    }
}